package com.laozhao.msas.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.Map;

import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.JXRootPane;
import org.jdesktop.swingx.JXStatusBar;
import org.jdesktop.swingx.JXTaskPane;
import org.jdesktop.swingx.JXTaskPaneContainer;

import com.laozhao.component.ViewUtil;
import com.laozhao.msas.action.TaskAction;
import com.laozhao.msas.util.InfiniteProgressPanel;
import com.laozhao.msas.util.Messages;

public class MsasApp implements Action{

	private JXFrame frame;
	private JXRootPane rootPane;
	protected InfiniteProgressPanel busyPane;
	private JMenuBar menuBar;
	private JXTaskPane taskPane;
	private JTabbedPane mainPane;
	private JXStatusBar statusBar;
	
//	private JTabbedPane tabbedPane ;

	private Map<String, Object> map = new HashMap<String, Object>();
//	private ActionListener menuListener;
//	private ActionListener menuListener;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MsasApp window = new MsasApp();
					window.initFrame();
					window.initMenu();
					window.initview();
					window.frame.setVisible(true);
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MsasApp() {
//		initFrame();
//		initMenu();
//		initview();
	}

	private void initMenu() {
		// TODO Auto-generated method stub
		
	}

	private void initFrame() {
		// create 
		frame = new JXFrame();
		rootPane = new JXRootPane();
		busyPane = new InfiniteProgressPanel(Messages.getString("general.wait.message"));
		
		//config
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLocationRelativeTo(null);
		
		frame.setRootPane(rootPane);	
		frame.setGlassPane(busyPane);		
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initview() {
		
		
		JXStatusBar statusBar = new JXStatusBar();
		frame.getRootPaneExt().getContentPane().add(statusBar, BorderLayout.SOUTH);
		
//		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		JTabbedPane tabbedPane = ViewUtil.loadTabbedPane("/config/TabbedPane.xml");
		frame.getRootPaneExt().getContentPane().add(tabbedPane, BorderLayout.CENTER);
		
//		JXTaskPaneContainer taskPaneContainer = new JXTaskPaneContainer();
		JXTaskPaneContainer taskPaneContainer = ViewUtil.loadTaskPaneContainer("/config/TaskMenu.xml", MsasApp.class);
		ApplicationActionMap map = ApplicationActionMap.getInstance();
		JXTaskPane systemGroup = new JXTaskPane("system");
		systemGroup.add(map.get("email"));
		systemGroup.add(map.get("delete"));
		taskPaneContainer.add(systemGroup);
		frame.getRootPaneExt().getContentPane().add(new JScrollPane(taskPaneContainer), BorderLayout.WEST);
//		taskPane = new JXTaskPane();
//		taskPaneContainer.add(taskPane);
//		taskPane.add();
		
		JMenuBar menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);
		
		JMenu menu = new JMenu("接线业务");
		menuBar.add(menu);
		
		JMenuItem menuItem = new JMenuItem("咨询");
		menu.add(menuItem);
//		frame.pack();
		frame.setSize(700, 500);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
//		tabbedPane.addTab(e.getActionCommand(), new JLabel(e.getActionCommand()+e.getWhen()));
//		tabbedPane.addTab("444444", new JLabel("5555555555"));
	}

	@Override
	public Object getValue(String key) {
		return map.get(key);
	}

	@Override
	public void putValue(String key, Object value) {
		map.put(key, value);
	}

	@Override
	public void setEnabled(boolean b) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isEnabled() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void addPropertyChangeListener(PropertyChangeListener listener) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void removePropertyChangeListener(PropertyChangeListener listener) {
		// TODO Auto-generated method stub
		
	}

}
